<template>
<Select v-bind="$attrs" v-on="$listeners" v-model="modelVal">
    <Option v-for="item in data" :value="item.value" :key="item.value">{{ item.label }}</Option>
</Select>
</template>

<script>
export default {
    props: {
        value: {
            type: [String, Array, Number]
        },
        data: {
            type: Array,
            default: []
        }
    },
    data() {
        return {
            modelVal: ""
        }
    },
    watch: {
        value: function (val) {
            this.modelVal = val
        }
    },
    created() {
        let selectedItem = this.data.find(d => d.selected)
        if (selectedItem) {
            this.modelVal = selectedItem.value
            this.$emit("on-change", selectedItem)
        }
    }
}
</script>

<style lang="less" scoped>

</style>
